#ifndef __RPATHPLAN_ASTAR_H__
#define __RPATHPLAN_ASTAR_H__

#include "RPathPlan.h"
#include "RRangeScan.h"
#include "rtk/RMap.h" 
#include <random>
#include <vector>

namespace rtk {
    // 染色体定义（路径节点索引序列）
    typedef std::vector<uint32_t> Chromosome;
    typedef std::vector<Chromosome> Population;

    class RPathPlan_astar : public RPathPlan {
    public:
        RPathPlan_astar();
        ~RPathPlan_astar() override;
        int pathPlan() override;
        int planBeg() override;
        int planStep() override;
        int planStepBackward() override;

    private:
        class GeneticData {
        public:
            GeneticData(RMap* map);
            Population initPopulation(int size);
            double calculateFitness(const Chromosome& chrom);
            Chromosome selection(const Population& pop, const std::vector<double>& fit);
            uint32_t generateValidNode();
            void validPath(Chromosome& chrom);
        private:
            RMap* m_map;
            uint32_t m_startIdx;
            uint32_t m_endIdx;
            int m_width;
            int m_height;
            std::mt19937 m_rng;
        };
        GeneticData* m_geneticData;
        RRangeScan  m_scan;
    };
} // namespace rtk

#endif // __RPATHPLAN_ASTAR_H__